﻿<div class="page-header">
    <div class="row">
        <div class="col-md-8">
            <h2>{{::vm.translate.get('Stock management for warehouse')}} <strong>{{ vm.selectedWarehouse.name }}</strong></h2>
        </div>
        <div class="col-md-4 text-right">
            <form class="form-inline">
                <div class="form-group">
                    <label>{{::vm.translate.get('Warehouse')}}</label>
                    <select class="form-control" ng-change="vm.wareHouseSelectChange()" ng-model="vm.selectedWarehouse"
                            ng-options="warehouse as warehouse.name for warehouse in vm.warehouses"></select>
                </div>
                <a ui-sref="warehouse-manage-products({warehouseId: vm.selectedWarehouse.id})">Manage products in warehouse</a>
            </form>
        </div>
    </div>
</div>

<table ng-if="vm.selectedWarehouse" class="table table-striped" st-pipe="vm.getStocks" st-table="vm.stocks">
    <thead>
        <tr>
            <th>{{::vm.translate.get('Product Name')}}</th>
            <th>{{::vm.translate.get('Product Sku')}}</th>
            <th class="text-right">{{::vm.translate.get('Current Quantity')}}</th>
            <th class="text-right">(+/-) Adjusted Quantity</th>
            <th>Notes</th>
            <th>{{::vm.translate.get('Stock History')}}</th>
        </tr>
        <tr>
            <th>
                <div class="form-group">
                    <input class="form-control" st-search="ProductName" />
                </div>
            </th>
            <th>
                <div class="form-group">
                    <input class="form-control" st-search="ProductSku" />
                </div>
            </th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
        </tr>
        <tr>
            <th ng-show="!vm.isLoading" colspan="6">{{vm.tableStateRef.pagination.totalItemCount | number:0}} records found</th>
        </tr>
    </thead>
    <tbody ng-show="!vm.isLoading">
        <tr ng-repeat="item in vm.stocks">
            <td>{{item.productName}}</td>
            <td>{{item.productSku}}</td>
            <td class="text-right">{{item.quantity}}</td>
            <td>
                <input class="form-control text-right" ng-model="item.adjustedQuantity" />
            </td>
            <td>
                <input class="form-control" ng-model="item.note" />
            </td>
            <td>
                <a ui-sref="stock-history({warehouseId: vm.selectedWarehouse.id, productId : item.productId})">{{::vm.translate.get('View History')}}</a>
            </td>
        </tr>
    </tbody>
    <tbody ng-show="vm.isLoading">
        <tr>
            <td colspan="6" class="text-center">Loading ... </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td class="text-center" st-pagination="" st-items-by-page="50" st-displayed-pages="10" colspan="6"></td>
        </tr>
    </tfoot>
</table>
<div class="text-right">
    <button class="btn btn-primary" ng-click="vm.save()"><span class="glyphicon glyphicon-ok"></span> {{::vm.translate.get('Save')}}</button>
</div>
